import { createRouter, createWebHashHistory } from 'vue-router'
import Login from '../views/login.vue'
import layout from '../layout/layout.vue'
import useCounter from "../stores/counter";

const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path: '/',
      name: 'logo',
      component: Login
    },
    {
      path: '/home',
      name: 'home',
      component: layout,
      redirect: '/home',
      meta:{title: '首页', icon:'HomeFilled', typeCode: 'home'},
      children: [
        {
          path: '/home',
          name: 'home',
          component: () => import('../views/home.vue'),
          meta:{title: '首页', icon:''},
        },
        {
          path: '/answerBase',
          name: 'answerBase',
          component: () => import('../views/answerBase.vue'),
          meta:{title: '题库', icon:'', builtIn: true},
        }
      ]
    },
    {
      path: '/user',
      name: 'user',
      component: layout,
      meta: {title: '用户', icon: 'Avatar', typeCode: 'user'},
      children: [
        {
          path: '/user',
          name: 'user',
          meta: {title: '用户', icon: ''},
          component: () => import('../views/User.vue')
        }
      ]
    },
    {
      path: '/system',
      name: 'system',
      component: layout,
      // redirect: '/systemSet',
      meta: {title: '系统设置', icon: 'ChromeFilled', typeCode: 'system'},
      children: [
        {
          path: '/system',
          name: 'system',
          meta: {title: '系统设置', icon: ''},
          component: () => import('../views/system.vue')
        }
      ]
    }
  ]
})


router.beforeEach((to, from, next) => {
  // console.log(to, from)
  const pathNameStore = useCounter()
  pathNameStore.pathName =to.meta.title
  next()
})

export default router
